<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class FcController extends Controller{
    
    public function actionIndex(){
        
         $sql = "SELECT a.id,a.title,a.content,a.min_banner_url,a.ctime
                    FROM xyh_article as a
                    WHERE a.status = 1 and  a.is_hot=2  order by a.ctime DESC";
         
         
        $criteria=new CDbCriteria();
        $result = Yii::app()->db->createCommand($sql)->query();
        $pages=new CPagination($result->rowCount);
        $pages->pageSize=5; 
        $pages->applyLimit($criteria); 
        $result=Yii::app()->db->createCommand($sql." LIMIT :offset,:limit"); 
        $result->bindValue(':offset', $pages->currentPage*$pages->pageSize); 
        $result->bindValue(':limit', $pages->pageSize); 
        $posts=$result->queryAll();
        
        
        //热点
        $sqlHot = "SELECT a.id,a.title,a.content,a.banner_url,a.ctime
               FROM xyh_article as a
               WHERE a.status = 1 and a.is_hot =1 ";
        
        $dataHot = Yii::app()->db->createCommand($sqlHot)->queryAll();
       
        $dataHot[0]['content']  =mb_substr(strip_tags($this->trimall($dataHot[0]['content'])),0,180,'utf-8'); 
        $dataHot[0]['ctime'] = date('Y-m-d H:00',$dataHot[0]['ctime']);   
        
        
        foreach ($posts as $k=>$v){
            
            $posts[$k]['content']  =mb_substr(strip_tags($this->trimall($posts[$k]['content'])),0,40,'utf-8'); 
            $posts[$k]['ctime'] = date('Y-m-d H:00',$v['ctime']);   
        }
     
        
          //排行
        $sqlRightList ="SELECT n.id,n.title
                        FROM xyh_article as n
                        WHERE n.status = 1 and  n.is_hot=2  ORDER by n.id DESC LIMIT 6  ";
        
        $dataRightList = Yii::app()->db->createCommand($sqlRightList)->queryAll();
        
        
       
        
        $this->render('index',array( 
                'posts'=>$posts, 
                'pages'=>$pages,
                'dataHot'=>$dataHot[0],
                'dataRightList'=>$dataRightList
        ));
        
        
     
    }
    
    
    
    public function actionView($NewId){
        
        
       
        if($NewId){
            
            $sql = "SELECT n.id,n.title,n.content,n.ctime,a.rename FROM xyh_article as n"
                    . " LEFT JOIN xyh_alumni as a on a.id = n.alumni_id"
                    . " WHERE n.id = {$NewId} and  n.status = 1 and n.is_del = 2";
            
            $dataNew = Yii::app()->db->createCommand($sql)->queryRow();       
         //   p_e($dataNew);
    
            $this->render('view',array('dataNew'=>$dataNew));
        }
        
        
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    function trimall($str)//删除空格
        {
            $qian=array(" "," ","\t","\n","\r","&nbsp;");
            $hou=array("","","","","","");
            return str_replace($qian,$hou,$str);    
        }
    
    
}